﻿using System.Drawing;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Overload.Entities;

namespace Overload.Testing.Entities
{
    [TestFixture]
    public class TerrainTests
    {
        private Terrain terrain;

        #region Test Initialization: Create Terrain

        [SetUp]
        public void TestCreateTerrain()
        {
            World world = new World(10, 20);
            terrain = new Terrain(world, 60);
        }

        #endregion

        #region Test: Terrain Has Image Component

        [Test]
        public void TestTerrainHasImageComponent()
        {
            Assert.That(terrain.RequiredComponents, Has.Member(typeof(Moebius.Components.Image)));
        }

        #endregion
        #region Test: Can Convert From Tile Location to Screen Space

        [Test]
        public void TestMapTileToScreenSpace()
        {
            Point tileLocation = new Point(-4, -1);
            Point correctScreenLocation = new Point(135, 130);

            Size tileSize = new Size(60, 52);
            RectangleF calculatedScreenSpace = terrain.CalculateTileScreenPosition(tileLocation);

            Assert.That(calculatedScreenSpace.X, Is.EqualTo(correctScreenLocation.X).Within(0.5f));
            Assert.That(calculatedScreenSpace.Y, Is.EqualTo(correctScreenLocation.Y).Within(0.5f));
            Assert.That(calculatedScreenSpace.Width, Is.EqualTo(tileSize.Width).Within(1));
            Assert.That(calculatedScreenSpace.Height, Is.EqualTo(tileSize.Height).Within(1));
        }

        #endregion
        #region Test: Convert From Screen Space To World Space

        [Test]
        public void TestConvertFromScreenSpaceToWorldSpace()
        {
            Point screenSpace = new Point(30, 40);
            Point expectedTileCoordinates = new Point(0, 0);

            Point calculatedTileCoordinates = terrain.CalculateTileCoordinatesFromScreenSpace(screenSpace);  
  
            Assert.That(calculatedTileCoordinates, Is.EqualTo(expectedTileCoordinates));
        }

        #endregion
    }
}